//
//  ExploreTableViewCell.m
//  EDPS
//
//  Created by 张维扬 on 15/11/26.
//  Copyright © 2015年 张维扬. All rights reserved.
//

#import "ExploreTableViewCell.h"
#import "Masonry.h"
#import "UIImageView+WebCache.h"
@interface ExploreTableViewCell ()
@property (nonatomic, retain) UIImageView *cover_image;//图片
@property (nonatomic, retain) UILabel *name;//标题
@property (nonatomic, retain) UILabel *count;//开始时间//天数// 浏览数
@property (nonatomic ,retain) UILabel *popular_place_str;// 地点
@property (nonatomic, retain) UILabel *label;//竖线label

@property (nonatomic, retain) UIImageView *avatar_m;// 用户头像
@property (nonatomic, retain) UILabel *user_name; // 用户名
@end
@implementation ExploreTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.contentView.backgroundColor = RGBA(253, 244, 233, 1);
        self.cover_image = [[UIImageView alloc] init];
        [self.contentView addSubview:self.cover_image];
        self.cover_image.layer.cornerRadius = 5;
        self.cover_image.clipsToBounds = YES;
        
        self.name = [[UILabel alloc] init];
        [self.name setFont:[UIFont fontWithName:@"Helvetica-Bold" size:18]];
        self.name.textColor = [UIColor whiteColor];
        [self.cover_image addSubview:self.name];
        
        self.count = [[UILabel alloc] init];
        [self.count setFont:[UIFont systemFontOfSize:12]];
        self.count.textColor = [UIColor whiteColor];
        [self.cover_image addSubview:self.count];
        
        self.popular_place_str = [[UILabel alloc] init];
        [self.popular_place_str setFont:[UIFont systemFontOfSize:12]];
        self.popular_place_str.textColor = [UIColor whiteColor];
        [self.cover_image addSubview:self.popular_place_str];
        
        
        self.label = [[UILabel alloc] init];
        self.label.layer.cornerRadius = 3;
        self.label.clipsToBounds = YES;
        self.label.backgroundColor = RGBA(62, 172, 190, 1);
        [self.cover_image addSubview:self.label];
        
        self.avatar_m = [[UIImageView alloc] init];
        [self.contentView addSubview:self.avatar_m];
        self.avatar_m.layer.cornerRadius = 15;
        self.avatar_m.clipsToBounds = YES;
        
        self.user_name = [[UILabel alloc] init];
        [self.contentView addSubview:self.user_name];
        [self.user_name setFont:[UIFont systemFontOfSize:12]];
        self.user_name.textColor =[UIColor whiteColor];
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    // 图片
    [self.cover_image mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.contentView).offset(10);
        make.bottom.mas_equalTo(self.contentView.mas_bottom).offset(-10);
        make.left.mas_equalTo(self.contentView.mas_left).offset(10);
        make.right.mas_equalTo(self.contentView.mas_right).offset(-10);
    }];
    // 标题
    [self.name mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.contentView).offset(10);
        make.left.mas_equalTo(self.cover_image.mas_left).offset(10);
        make.size.mas_equalTo(CGSizeMake(self.contentView.frame.size.width - 20, 40));
        
    }];
    // 颜色小条
    [self.label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.contentView).offset(50);
        make.left.mas_equalTo(self.cover_image.mas_left).offset(10);
        make.size.mas_equalTo(CGSizeMake(4, 30));
    }];
    // 开始时间 // 持续天数 // 浏览数
    [self.count mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.cover_image.mas_left).offset(20);
        make.top.mas_equalTo(self.contentView).offset(50);
        make.size.mas_equalTo(CGSizeMake(self.contentView.frame.size.width - 30, 15));
    }];
    
    // 地点
    [self.popular_place_str mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.cover_image.mas_left).offset(20);
        make.top.mas_equalTo(self.contentView).offset(65);
        make.size.mas_equalTo(CGSizeMake(self.contentView.frame.size.width - 30, 15));
    }];
    
    // 用户头像
    [self.avatar_m mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.mas_equalTo(self.cover_image.mas_left).offset(10);
        make.bottom.mas_equalTo(self.cover_image.mas_bottom).offset(-10);
        make.size.mas_equalTo(CGSizeMake(30, 30));
        
    }];
    // 用户名
    [self.user_name mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.avatar_m.mas_centerY);
        make.left.mas_equalTo(self.cover_image.mas_left).offset(50);
        make.size.mas_equalTo(CGSizeMake(300, 20));
        
    }];
}


- (void)setModel:(ExploreModel *)model
{
    if (_model != model) {
        _model = model;
    }
    [self.cover_image sd_setImageWithURL:[NSURL URLWithString:model.cover_image] placeholderImage:[UIImage imageNamed:@"hold"]];
    
    self.name.text = model.name;
    self.count.text = [NSString stringWithFormat:@"%@  %@天 %@浏览", model.first_day, model.day_count.stringValue, model.view_count.stringValue];
    self.popular_place_str.text = model.popular_place_str;
    
    
}
- (void)setImgName_Model:(imgNameModel *)imgName_Model
{
    if (_imgName_Model != imgName_Model) {
        _imgName_Model = imgName_Model;
    }
    [self.avatar_m sd_setImageWithURL:[NSURL URLWithString:imgName_Model.avatar_m] placeholderImage:[UIImage imageNamed:@"hold"]];
    self.user_name.text = [NSString stringWithFormat:@"by %@", imgName_Model.name];
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
